<?php
class comment extends skeleton {
	function css($echo = true) {
		$session = get_global($_SESSION, 'commentAlt');
		$css = ' id="comment-'.$this->get_id().'"'.$session;
		
		$_SESSION['commentAlt'] = (empty($session)) ? ' class="alt"' : '';
		
		if ($echo === true) echo $css;
		else return $css;
	}
	
	function get_author($format = true, $options = array()) {
		return $this->author;
	}
	
	function get_author_link($format = true, $options = array()) {
		$link = $this->author_site;
		if (empty($link)) return $this->get_author();
		
		if ($format === true) {
			$options = array_merge(array(
				'text' => $this->get_author(),
				'title' => $this->get_author().'\'s site',
				'class' => ''
			), (array)$options);
			$options['href'] = $link;
			
			$link = make_link($options);
		}
		
		return $link;
	}
	
	function get_content($format = true) {
		return ($format === true) ? autop(abbr($this->content)) : $this->content;
	}
	
	function get_email() {
		return $this->author_email;
	}
	
	function get_date($format = 'F j, Y @ g:ia') {
		return get_date($format, $this->date, true);
	}
	
	function get_gravatar($format = true, $options = array()) {
		$options = array_merge(array(
			'size' => 40,
			'alt' => 'Gravatar',
			'class' => 'gravatar'
		), (array)$options);
		$gravatar = get_gravatar($this->author_email, $options['size']);
		
		if ($format === true) {
			$gravatar = '<img src="'.$gravatar.'" alt="'.$options['alt'].'" class="'.$options['class'].'" />';
		}
		
		return $gravatar;
	}
	
	function get_ip() {
		return $this->author_ip;
	}
	
	function get_permalink($format = true, $options = array()) {
		$permalink = $this->get_post_object()->get_permalink(false).'#comment-'.$this->get_id();
		
		if ($format === true) {
			$options = array_merge(array(
				'text' => 'permalink to this comment',
				'title' => 'Permalink to this comment',
				'class' => ''
			), (array)$options);
			$options['href'] = $permalink;
			
			$permalink = make_link($options);
		}
		
		return $permalink;
	}
	
	function get_post_object() {
		global $mysql;
		if (!isset($this->post)) $this->post = get_single_item(array(
			'table' => POSTS,
			'class' => 'post',
			'where' => '`post_id` = "'.$this->post_id.'"'
		));
		
		return $this->post;
	}
	
	function get_status() {
		return (bool)$this->status;
	}
	
	function get_website() {
		return $this->author_site;
	}
	
	function the_author() {
		echo $this->get_author();
	}
	
	function the_author_link($format = true, $options = array()) {
		echo $this->get_author_link($format, $options);
	}
	
	function the_content($format = true) {
		echo $this->get_content($format);
	}
	
	function the_email() {
		echo $this->get_email();
	}
	
	function the_date($format = 'F j, Y @ g:ia') {
		echo $this->get_date($format);
	}
	
	function the_gravatar($format = true, $options = array()) {
		echo $this->get_gravatar($format, $options);
	}
	
	function the_ip() {
		echo $this->get_ip();
	}
	
	function the_permalink($format = true, $options = array()) {
		echo $this->get_permalink($format, $options);
	}
	
	function the_website() {
		echo $this->get_website();
	}
}
?>